package com.xhwl.logistics.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;


/**
 * description 批量导入线程
 * @author wagnyiling
 * @since 2022-9/23
 */
@Configuration
public class CustomThreadPool {
    @Bean
    public ThreadPoolExecutor posterInfoThread() {
        /**
         * 线程池配置:
         * 核心线程数20
         * 最大线程数50
         * 线程空闲保活时间3000
         * 队列大小100
         * 拒绝策略:调用者执行
         */
        ThreadPoolExecutor executor = new ThreadPoolExecutor(20, 50, 3000, TimeUnit.SECONDS,
                new ArrayBlockingQueue<Runnable>(100), Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.CallerRunsPolicy());
        return executor;

    }
}
